package com.wulin;

import com.wulin.mapper.EnvironmentDataMapper;
import com.wulin.mapper.HarvestDataMapper;
import com.wulin.mapper.PestDiseaseDataMapper;
import com.wulin.mapper.UserDataMapper;
import com.wulin.pojo.EnvironmentData;
import com.wulin.pojo.HarvestData;
import com.wulin.pojo.PestDiseaseData;
import com.wulin.pojo.UserData;
import jdk.management.resource.internal.inst.SocketOutputStreamRMHooks;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLOutput;
import java.util.List;

public class Demo {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        SqlSession sqlSession =sqlSessionFactory.openSession();

        EnvironmentDataMapper environmentDataMapper = sqlSession.getMapper(EnvironmentDataMapper.class);
        PestDiseaseDataMapper pestDiseaseDataMapper = sqlSession.getMapper(PestDiseaseDataMapper.class);
        HarvestDataMapper harvestDataMapper = sqlSession.getMapper(HarvestDataMapper.class);
        UserDataMapper userDataMapper = sqlSession.getMapper(UserDataMapper.class);

        List<UserData> users = userDataMapper.selectAll();
        List<EnvironmentData> environs = environmentDataMapper.selectById(1);
        List<PestDiseaseData> pests = pestDiseaseDataMapper.selectAll();
        List<HarvestData> harvests = harvestDataMapper.selectAll();

        System.out.println(users);
        System.out.println(environs);
        System.out.println(pests);
        System.out.println(harvests);
        sqlSession.close();
    }
}
